12 / 13

Why can't you instantiate an Interface or Abstract Class?

Difficulty: 1/10

Instantiation Restrictions

An interface cannot normally be instantiated because it defines a contract rather than a complete concrete object implementation. An abstract class cannot be instantiated because it may contain abstract operations whose behavior is intentionally incomplete. The runtime needs a concrete type with all required behavior defined before it can create a normal object. However, a reference of interface or abstract-class type can point to a concrete implementing or derived object.

javascript
  1. 1

    Interfaces represent contracts rather than directly constructible concrete objects.

  2. 2

    Abstract classes can contain incomplete behavior.

  3. 3

    Concrete subclasses provide the missing behavior.

  4. 4

    Interface and abstract-class references can still point to concrete objects.

  5. 5

    This supports abstraction and runtime polymorphism.

Follow-up Questions

  • Can an abstract class have a constructor?
  • Can an abstract class be fully implemented?
  • Why can an interface reference point to an object?
  • What is upcasting?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.